home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / WINSOCK.PAK / SOCKBOUT.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  148 lines

  1. /*-----------------------------------------------------------------------*\
  2. | OWLSock Demo For Windows v1.0                                           |
  3. --------------------------------------------------------------------------|
  4. | Written By:  Paul Pedriana                                              |
  5. | Date:        May 7, 1995.                                               |
  6. | Copyright:   Copyright (c) 1995 by Paul Pedriana.  All Rights Reserved. |
  7. | UserID(s):   70541,3223                                                 |
  8. |              70541.3223@compuserve.com                                  |
  9. --------------------------------------------------------------------------|
  10. | This OWLSock demo is an application that demonstrates some features     |
  11. | of OWLSock.  It uses only asynchronous (non-blocking) Winsock calls,    |
  12. | and uses OWLSock socket 'external' notification rather than internal    |
  13. | notification.  External notification is the way most Winsock apps do    |
  14. | FD_XXX notifications; see the OWLSock docs for more info.               |
  15. --------------------------------------------------------------------------|
  16. | Notes on this module:                                                   |
  17. |    This module present the about box and some related information.      |
  18. \*-----------------------------------------------------------------------*/
  19.  
  20. #include <owl/pch.h>
  21. #if !defined(OWL_STATIC_H)
  22. # include <owl/static.h>
  23. #endif
  24. #if defined(BI_PLAT_WIN16)
  25. # include <ver.h>
  26. #endif
  27. #include "sockbout.h"
  28.  
  29.  
  30. ProjectRCVersion::ProjectRCVersion (TModule *module)
  31. {
  32.     char    appFName[255];
  33.     char    subBlockName[255];
  34.     DWORD   fvHandle;
  35.     UINT    vSize;
  36.  
  37.     FVData = 0;
  38.  
  39.     module->GetModuleFileName(appFName, sizeof(appFName));
  40.     OemToAnsi(appFName, appFName);
  41.     DWORD dwSize = ::GetFileVersionInfoSize(appFName, &fvHandle);
  42.     if (dwSize) {
  43.         FVData  = (void FAR *)new char[(UINT)dwSize];
  44.         if (::GetFileVersionInfo(appFName, fvHandle, dwSize, FVData)) {
  45.             // Copy string to buffer so if the -dc compiler switch (Put constant strings in code segments)
  46.             // is on VerQueryValue will work under Win16.  This works around a problem in Microsoft's ver.dll
  47.             // which writes to the string pointed to by subBlockName.
  48.             strcpy(subBlockName, "\\VarFileInfo\\Translation"); 
  49.             if (!::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&TransBlock, &vSize)) {
  50.                 delete FVData;
  51.                 FVData = 0;
  52.             } else
  53.                 // Swap the words so wsprintf will print the lang-charset in the correct format.
  54.                 *(DWORD *)TransBlock = MAKELONG(HIWORD(*(DWORD *)TransBlock), LOWORD(*(DWORD *)TransBlock));
  55.         }
  56.     }
  57. }
  58.  
  59.  
  60. ProjectRCVersion::~ProjectRCVersion ()
  61. {
  62.     if (FVData)
  63.         delete FVData;
  64. }
  65.  
  66.  
  67. bool ProjectRCVersion::GetProductName (LPSTR &prodName)
  68. {
  69.     UINT    vSize;
  70.     char    subBlockName[255];
  71.  
  72.     wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"ProductName");
  73.     return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&prodName, &vSize) : false;
  74. }
  75.  
  76.  
  77. bool ProjectRCVersion::GetProductVersion (LPSTR &prodVersion)
  78. {
  79.     UINT    vSize;
  80.     char    subBlockName[255];
  81.  
  82.     wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"ProductVersion");
  83.     return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&prodVersion, &vSize) : false;
  84. }
  85.  
  86.  
  87. bool ProjectRCVersion::GetCopyright (LPSTR ©right)
  88. {
  89.     UINT    vSize;
  90.     char    subBlockName[255];
  91.  
  92.     wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"LegalCopyright");
  93.     return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)©right, &vSize) : false;
  94. }
  95.  
  96.  
  97. bool ProjectRCVersion::GetDebug (LPSTR &debug)
  98. {
  99.     UINT    vSize;
  100.     char    subBlockName[255];
  101.  
  102.     wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"SpecialBuild");
  103.     return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&debug, &vSize) : false;
  104. }
  105.  
  106. //********************************************************************************************
  107. DlgSockDemoAbout::DlgSockDemoAbout (TWindow *parent, TResId resId, TModule *module)
  108.     : TDialog(parent, resId, module)
  109. {
  110. }
  111.  
  112.  
  113. DlgSockDemoAbout::~DlgSockDemoAbout (){
  114.     Destroy();
  115. }
  116.  
  117.  
  118. void DlgSockDemoAbout::SetupWindow (){
  119.     LPSTR prodName = 0, prodVersion = 0, copyright = 0, debug = 0;
  120.  
  121.     TStatic* versionCtrl = new TStatic(this, IDC_VERSION, 255);
  122.     TStatic* copyrightCtrl = new TStatic(this, IDC_COPYRIGHT, 255);
  123.     TStatic* debugCtrl = new TStatic(this, IDC_DEBUG, 255);
  124.  
  125.     TDialog::SetupWindow();
  126.  
  127.     ProjectRCVersion applVersion(GetModule());
  128.  
  129.     if (applVersion.GetProductName(prodName) && applVersion.GetProductVersion(prodVersion)) {
  130.         char    buffer[255];
  131.         char    versionName[128];
  132.  
  133.         buffer[0] = '\0';
  134.         versionName[0] = '\0';
  135.  
  136.         versionCtrl->GetText(versionName, sizeof(versionName));
  137.         wsprintf(buffer, "%s %s %s", prodName, versionName, prodVersion);
  138.  
  139.         versionCtrl->SetText(buffer);
  140.     }
  141.  
  142.     if (applVersion.GetCopyright(copyright))
  143.         copyrightCtrl->SetText(copyright);
  144.  
  145.     if (applVersion.GetDebug(debug))
  146.         debugCtrl->SetText(debug);
  147. }
  148.